<template>
  <a-spin :spinning="loading">
    <div>
      <a-form-model
        class="fromModels"
        ref="investmentTeamModel"
        layout="vertical"
        :labelCol="{ span: 4 }"
        :wrapperCol="{ span: 12, offset: 1 }"
      >
        <a-form-model-item label="招商团队开关">
          <a-radio-group v-model="status">
            <a-radio :value="1"> 开 </a-radio>
            <a-radio :value="0"> 关 </a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="税费费率">
          <a-input v-model="config.tax_rate">
            <div slot="addonAfter">万</div>
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="达标最低级别">
          <a-select v-model="config.level_id">
            <a-select-option v-for="(item, index) in levelArrs" :key="index" :value="item.level">{{
              item.name
            }}</a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item label="达标最小金额">
          <a-input v-model="config.min_amount">
            <div slot="addonAfter">元</div>
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="达标最大金额">
          <a-input v-model="config.max_amount">
            <div slot="addonAfter">元</div>
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="最小分润">
          <a-input v-model="config.min_rate">
            <div slot="addonAfter">%</div>
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="最大分润">
          <a-input v-model="config.max_rate">
            <div slot="addonAfter">%</div>
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="用户代数">
          <a-input v-model="config.max_people">
            <div slot="addonAfter">代</div>
          </a-input>
        </a-form-model-item>
        <a-form-model-item label="无条件限制级别">
          <a-select v-model="config.nolevel_id">
            <a-select-option v-for="(item, index) in levelArrs" :key="index" :value="item.level">{{
              item.name
            }}</a-select-option>
          </a-select>
        </a-form-model-item>

        <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
          <a-button type="primary" @click="whites">提交</a-button>
          <a-button type="primary" @click="reset">重置</a-button>
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-spin>
</template>

<script>
import { getRebateApi, setRebateApi, getLevelApi } from '@/api/return.js'
export default {
  name: 'investmentTeam',

  data() {
    return {
      loading: false,
      config: {
        level_id: 0,
        tax_rate: '0',
        max_amount: '',
        max_people: '',
        max_rate: '',
        min_amount: '',
        min_rate: '',
        nolevel_id: ''
      },
      status: 1,
      levelArrs: [],
      disableds: true
    }
  },
  created() {
    this.getPrivacyAgreementInfo()
    this.getLevelApi()
  },
  methods: {
    reset() {
      this.getPrivacyAgreementInfo()
      this.getLevelApi()
    },
    getLevelApi() {
      getLevelApi({
        brand_id: process.env.VUE_APP_BRAND_ID
      }).then(res => {
        this.levelArrs = res.data
      })
    },
    getPrivacyAgreementInfo() {
      this.loading = true
      getRebateApi({
        type: 'level_team_rebate',
        brand_id: process.env.VUE_APP_BRAND_ID
      })
        .then(res => {
          this.config = res.data.config
          this.status = res.data.status
        })
        .finally(() => {
          this.loading = false
        })
    },
    whites() {
      this.setDatas()
    },
    setDatas() {
      setRebateApi({
        type: 'level_team_rebate',
        brand_id: process.env.VUE_APP_BRAND_ID,
        status: this.status,
        data: this.config
      }).then(res => {
        this.getPrivacyAgreementInfo()
        this.getLevelApi()
        this.$message.success('操作成功')
      })
    }
  }
}
</script>

<style lang="less" scoped></style>
